'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up (queryInterface, Sequelize) {
    /**
     * Add altering commands here.
     *
     * Example:
     * await queryInterface.createTable('users', { id: Sequelize.INTEGER });
     */
    // 在子表的迁移文件中
    await queryInterface.addConstraint('attr_value', {
      fields: ['attrId'],
      type: 'foreign key',
      name: 'custom_fkey_name',
      references: {
        table: 'attr',
        field: 'id'
      },
      onDelete: 'CASCADE' // 这里也要配置
    });
  },

  async down (queryInterface, Sequelize) {
    /**
     * Add reverting commands here.
     *
     * Example:
     * await queryInterface.dropTable('users');
     */
  }
};
